function gadget:GetInfo()
  return {
    name      = "Ingame Upspring",
    desc      = "Description here.",
    author    = "Rafal",
    date      = "Dec, 2011",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = false
  }
end

VFS.Include("luarules/utils/debug.lua")
--for tableName, v in pairs(_G) do Spring.Echo (tableName .. ": " .. tostring(v)) end
--for tableName, ud in pairs(UnitDefNames) do printTable ("UnitDefs["..tableName.."].moveData", ud.moveData) end
--for tableName, ud in pairs(UnitDefNames) do printTable ("UnitDefs["..tableName.."].customParams", ud.customParams) end
--for tableName, ud in pairs(UnitDefNames) do printTable ("UnitDefs["..tableName.."].myCustomParams", ud.myCustomParams) end
--for tableName, wd in pairs(WeaponDefNames) do printTable ("WeaponDefs["..tableName.."].myCustomParams", wd.myCustomParams) end
--for tableName, ud in pairs(UnitDefNames) do printTable ("UnitDefs["..tableName.."]", ud) end
--for tableName, wd in pairs(WeaponDefNames) do printTable ("WeaponDefs["..tableName.."]", wd) end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- COMMON

-- CONFIG

local GRID_HEIGHT = 200.0
local GRID_SCALE = 40.0
local GRID_FACTOR = 16
local GRID_SIZE = 5
local AXES_LENGTH = 20
local AXES_COLOR = { 0.0, 1.0, 0.0, 1.0 }
local GRID_MAIN_COLOR = { 1.0, 1.0, 0.3, 1.0 }
local GRID_COLOR = { 1.0, 1.0, 0.3, 0.5 }

-- COMMON
if (gadgetHandler:IsSyncedCode()) then
-- SYNCED

-- SYNCED
else
-- UNSYNCED



  

  local function DrawGrid()
    gl.PushMatrix()
    gl.Translate(0.0, GRID_HEIGHT, 0.0)
    gl.Scale(GRID_SCALE, GRID_SCALE, GRID_SCALE)
    
    local gridMainSize = math.floor(GRID_SIZE)
    local pGridSize =  GRID_SIZE * GRID_FACTOR
    local mGridSize = -pGridSize

    local vertices = {}
    if (gridMainSize >= 1) then  
      for i = 1, gridMainSize do
        local i8 = (i - 1) * 8
        local pi = i * GRID_FACTOR
        local mi = -pi
        vertices[i8+1] = { v = { mi, 0, mGridSize }} --vertical lines
        vertices[i8+2] = { v = { mi, 0, pGridSize }}
        vertices[i8+3] = { v = { pi, 0, mGridSize }}
        vertices[i8+4] = { v = { pi, 0, pGridSize }}
        vertices[i8+5] = { v = { mGridSize, 0, mi }} --horizontal lines
        vertices[i8+6] = { v = { pGridSize, 0, mi }}
        vertices[i8+7] = { v = { mGridSize, 0, pi }}
        vertices[i8+8] = { v = { pGridSize, 0, pi }}      
      end  
    end
    gl.Color(GRID_MAIN_COLOR[1], GRID_MAIN_COLOR[2], GRID_MAIN_COLOR[3], GRID_MAIN_COLOR[4])
    gl.Shape(GL.LINES, vertices)
    
    local axesLength = AXES_LENGTH * GRID_FACTOR
    vertices = {
      {v = {-axesLength, 0, 0}},
      {v = { axesLength, 0, 0}},  
      {v = {0, -axesLength, 0}},
      {v = {0,  axesLength, 0}}, 
      {v = {0, 0, -axesLength}},
      {v = {0, 0,  axesLength}},       
    }
    gl.Color(AXES_COLOR[1], AXES_COLOR[2], AXES_COLOR[3], AXES_COLOR[4])
    gl.Shape(GL.LINES, vertices)
    
    gl.PopMatrix()
  end


  function gadget:DrawWorld()
    DrawGrid()
  
    local units = Spring.GetAllUnits()
    if (units) then
      --gl.Blending(false)
      --gl.Culling(GL.BACK)
      --gl.AlphaTest(GL.GREATER, 0.5)
      --gl.AlphaTest(true)
      gl.DepthTest(true)
      gl.DepthMask(true)
      --gl.DepthTest(GL.LEQUAL)
      --gl.PolygonMode(GL.FRONT_AND_BACK, GL.FILL)
      --gl.PolygonMode(GL.FRONT_AND_BACK, GL.LINE)
      gl.PushMatrix()
      --gl.ColorMask(false)  

      gl.Color(1, 1, 1, 1.0)
      gl.Translate(100.0, 500.0, 100.0)
      gl.Scale(20.0, 20.0, 20.0)
      --gl.Rotate(rotation, 0.0, 1.0, 0.0)
      
      local udID = UnitDefNames["c_factory"].id
      gl.UnitShape(udID, 0)
      
      gl.Translate(100.0, 0.0, 0.0)
      
      udID = UnitDefNames["c_heavytank"].id
      gl.Texture(0, "%" .. udID .. ":0")
      gl.UnitShape(udID, 0)
      gl.Texture(0,false);
      
      gl.Translate(100.0, 0.0, 0.0)      
      
      udID = UnitDefNames["c_battlecruiser"].id
      gl.Texture(0, "%" .. UnitDefNames["c_heavytank"].id .. ":0")
      gl.UnitShape(udID, 0)
      gl.Texture(0,false);
      
      --gl.ColorMask(true)
      gl.PopMatrix()
      
      for _, unitID in ipairs(units) do
        Spring.SetUnitNoDraw(unitID, true)
        Spring.UnitRendering.SetUnitLuaDraw(unitID, true)
      
      
      	local udID = Spring.GetUnitDefID(unitID)
        --local udID = UnitDefNames["c_factory"].id
      
        gl.PushMatrix()
        gl.PushMatrix()
        gl.UnitMultMatrix(unitID)
        --gl.ClipPlane(1, 0, -1, 0, 10)
        gl.PopMatrix()  
        
        --gl.ClipPlane(1, 0, -1, 0, 10)
        --gl.Texture(1, "%" .. UnitDefNames["c_heavytank"].id .. ":1")

        gl.Translate(100.0, 0.0, 0.0) 
        gl.Blending(false)
        --gl.AlphaTest(GL.GREATER, 0.5)
        gl.Color(1, 1, 1, 1.0)
        gl.Texture(0, "%" .. udID .. ":0")
        gl.Unit(unitID, false)
        
        --gl.Color(1, 1, 1, 1.0)
	--gl.ActiveTexture(1)
	--gl.TexEnv(GL.TEXTURE_ENV, GL.TEXTURE_ENV_COLOR, 0.0, 1.0, 0.0)
  
  	--	// Set material color
		--static const float cols[] = {1.0f, 1.0f, 1.0, 1.0f};
		--glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, cols)
		--glColor4fv(cols);
    
    --[[
    	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);

	// RGB = Texture * (1 - Alpha) + Teamcolor * Alpha
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
  
	glActiveTexture(GL_TEXTURE1);
	glEnable(GL_TEXTURE_2D);

	// RGB = Primary Color * Previous
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);

	// ALPHA = Current alpha * Alpha mask
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_MODULATE);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
	glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_ARB, GL_SRC_ALPHA);--]]  
  
  --[[
        gl.Translate(100.0, 0.0, 0.0)
        gl.Blending(false)        
        gl.Color(1, 1, 1, 1.0)
        gl.Texture(0, "%" .. udID .. ":0");
        gl.Unit(unitID, true)

        gl.Translate(100.0, 0.0, 0.0)   
        gl.UnitMultMatrix(unitID)
        
        --gl.Texture(0, "%" .. UnitDefNames["c_heavytank"].id .. ":0"); 

        gl.Blending(false)
        gl.Color(1, 1, 1, 1.0)
        gl.Texture(0, "%" .. udID .. ":0");        
        gl.UnitRaw(unitID, true)
  --]]      
        --gl.Translate(50.0, 0.0, 0.0)          
        --gl.UnitPiece(unitID, 2)   
        
        gl.PopMatrix()   
      end
      gl.ClipPlane(1, false)
      
      --gl.PolygonMode(GL.FRONT_AND_BACK, GL.FILL)
     	gl.AlphaTest(false) 
    end 
  end
  
-- UNSYNCED
end
-- COMMON